package com.jfinal.aceadmin.controller;

import com.jfinal.aceadmin.model.EmailImpl;
import com.jfinal.aceadmin.vo.EmailDetailVo;
import com.jfinal.core.Controller;
import com.jfinal.ext.route.ControllerBind;

@ControllerBind(controllerKey = "/admin/email", viewPath = "/admin/more_pages/")
public class EmailController extends Controller {

	public void detail() {
		long emailId = getParaToLong("emailId");
		EmailDetailVo emailDetailVo = EmailImpl.getDAO()
				.getEmailDetailVoByEmailId(emailId);
		setAttr("emailDetailVo", emailDetailVo);
		render("email_detail.html");
	}

	public void mark() {
		long emailId = getParaToLong("emailId");
		boolean result = EmailImpl.getDAO().markEmailAsReaded(emailId);
		renderJson("{\"success\":" + result + "}");
	}
	
	public void flag() {
		long emailId = getParaToLong("emailId");
		boolean result = EmailImpl.getDAO().flagEmail(emailId);
		renderJson("{\"success\":" + result + "}");
	}

	public void send() {
		String recipient = getPara("recipient");
		String subject = getPara("subject");
		String attachementFiles = getPara("attachementFiles");
		System.out.println("attachementFiles : " + attachementFiles);
		String message = getPara("message");
		String name = getSessionAttr("name");
		EmailImpl.getDAO().saveEmail(recipient,subject,message,attachementFiles,name);
		redirect("/admin/morepage/inbox");
		
	}
}
